<?php
namespace app\shoes\controller;
/** 控制器类引入区 **/
/** 模型类引入区 **/
use think\Db;
/**
 * 商品控制器
 * @package app\api\controller
 */
class Goods extends Auth
{
    public $noNeedLogin = [];

    /**
     * 获取商品分类
     */
    public function goods_cate()
    {
        if ($this->request->isPost()) {
            $data = Db::name('qt_goods_category')
                ->field('id,name,sort,description')
                ->where(['store_id' => $this->userInfo['store_id'], 'status' => '1'])
                ->order('sort  asc')
                ->select();
            $this->result('请求成功', $data, 200);
        }
        $this->result('无效的请求', '', 204);
    }

    /**
     * 获取商品
     */
    public function goods()
    {
        if ($this->request->isPost()) {
            $getData = $this->request->post();
            if (empty($getData['category_id'])) {
                $data = Db::name('qt_goods')
                    ->where(['store_id'=>$this->userInfo['store_id']])
                    ->field('id,name,price')
                    ->select();
            }else{
                $data = Db::name('qt_goods')
                    ->field('id,name,price')
                    ->where(['goods_category_id' => $getData['category_id'],'store_id'=>$this->userInfo['store_id']])
                    ->select();
            }
            $this->result('请求成功', $data, 200);
        }
        $this->result('无效的请求', '', 204);
    }

}
